﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Public;
using DLL;

namespace QLBanVe
{
    public partial class frmTraCuuChuyenBay : UserControl
    {
        public frmTraCuuChuyenBay()
        {
            InitializeComponent();
        }
        TuyenBayDLL tbdll = new TuyenBayDLL();

        SanBayDLL sbdll = new SanBayDLL();
        SanBayPublic sbp = new SanBayPublic();
        private void frmTraCuuChuyenBay_Load(object sender, EventArgs e)
        {
            Loadcb();
            
        }
        //Hàm load san bay vao combox
        private void Loadcb()
        {
            //load combox sân bay đi
            cbSanBayDi.DataSource = sbdll.LoadSanBay();
            cbSanBayDi.DisplayMember = "TenSanBay";
            cbSanBayDi.ValueMember = "MaSanBay";
            cbSanBayDi.SelectedIndex = -1;
        }
       
       

       

        private void cbSanBayDen_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void cbSanBayDi_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbSanBayDi.SelectedIndex != -1)//Lấy giá trị từ combox san bay đi
            {


                sbp.MaSanBay = cbSanBayDi.SelectedValue.ToString();//Lấy mã sân bay


                //load combox sân bay đến
                cbSanBayDen.DataSource = sbdll.LoadSanBayTheoTuyenBay(sbp);

                cbSanBayDen.DisplayMember = "SanBayDen";
                cbSanBayDen.ValueMember = "SanBayDen";

                cbSanBayDen.SelectedIndex = -1;

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ChuyenBayPublic cbp = new ChuyenBayPublic();
            ChuyenBayDLL cbdll = new ChuyenBayDLL();
            string SanBayDi = "";
            string SanBayDen = "";
            //Lấy giá trị combox
            if (cbSanBayDi.SelectedIndex != -1)
            {
                DataTable dt = new DataTable();
                int i = cbSanBayDi.SelectedIndex;
                dt = sbdll.LoadSanBay();
                DataRow dr;
                dr = dt.Rows[i];
                SanBayDi = dr["TenSanBay"].ToString();

            }
            if (cbSanBayDen.SelectedIndex != -1)//Lấy giá trị từ combox san bay đến
           {
                TuyenBayPublic tbp =new TuyenBayPublic();
                int i1 = cbSanBayDen.SelectedIndex;
                DataTable dt1 = new DataTable();
                dt1 = sbdll.LoadSanBayTheoTuyenBay(sbp);
                DataRow dr1;
                dr1 = dt1.Rows[i1];
                tbp.SanBayDen = dr1["SanBayDen"].ToString();
                SanBayDen = dr1["SanBayDen"].ToString();
            }
            cbp.SanBayDi = SanBayDi;
            cbp.SanBayDen = SanBayDen;
            dgwTim.DataSource = cbdll.ChuyenBay_Search(cbp);
           
        }

       

       
      


       
        
    }
}
